<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.9.1"/>
<title>OCILIB (C and C++ Driver for Oracle): Some OCILIB C++ sample codes</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
  $(window).load(resizeHeight);
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td style="padding-left: 0.5em;">
   <div id="projectname">OCILIB (C and C++ Driver for Oracle)
   &#160;<span id="projectnumber">4.2.1</span>
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.9.1 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>About</span></a></li>
      <li><a href="modules.html"><span>Documentation</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('group___ocilib_cpp_api_demo_list_application.html','');});
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">Some OCILIB C++ sample codes<div class="ingroups"><a class="el" href="group___ocilib_cpp_api.html">C++ API</a></div></div>  </div>
</div><!--header-->
<div class="contents">
<p>Here are some C++ samples code. More samples can be found under the demo folder of ocilib packages.</p>
<dl class="section user"><dt>Fetching data</dt><dd><div class="fragment"><div class="line"><span class="preprocessor">#include &lt;iostream&gt;</span></div>
<div class="line"></div>
<div class="line"><span class="preprocessor">#include &quot;ocilib.hpp&quot;</span></div>
<div class="line"></div>
<div class="line"><span class="keyword">using namespace </span><a class="code" href="namespaceocilib.html">ocilib</a>;</div>
<div class="line"></div>
<div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">void</span>)</div>
<div class="line">{</div>
<div class="line">    <span class="keywordflow">try</span></div>
<div class="line">    {</div>
<div class="line">        <a class="code" href="classocilib_1_1_environment.html#a83613d62908717ddf7d0ac797d63120a">Environment::Initialize</a>();</div>
<div class="line"></div>
<div class="line">        <a class="code" href="classocilib_1_1_connection.html">Connection</a> con(<span class="stringliteral">&quot;db&quot;</span>, <span class="stringliteral">&quot;usr&quot;</span>, <span class="stringliteral">&quot;pwd&quot;</span>);</div>
<div class="line"></div>
<div class="line">        <a class="code" href="classocilib_1_1_statement.html">Statement</a> st(con);</div>
<div class="line">        st.Execute(<span class="stringliteral">&quot;select * from all_users&quot;</span>);</div>
<div class="line"></div>
<div class="line">        <a class="code" href="classocilib_1_1_resultset.html">Resultset</a> rs = st.GetResultset();</div>
<div class="line">        <span class="keywordflow">while</span> (rs++)</div>
<div class="line">        {</div>
<div class="line">            std::cout &lt;&lt; <span class="stringliteral">&quot;UserName:&quot;</span> &lt;&lt; rs.<a class="code" href="classocilib_1_1_resultset.html#aeaea5cd57d9b6838f3887ed57338acb8">Get</a>&lt;<a class="code" href="namespaceocilib.html#a01daa07e307e429b66fb80f442362237">ostring</a>&gt;(<span class="stringliteral">&quot;username&quot;</span>) &lt;&lt; <span class="stringliteral">&quot; Created:&quot;</span> &lt;&lt; rs.<a class="code" href="classocilib_1_1_resultset.html#aeaea5cd57d9b6838f3887ed57338acb8">Get</a>&lt;<a class="code" href="namespaceocilib.html#a01daa07e307e429b66fb80f442362237">ostring</a>&gt;(<span class="stringliteral">&quot;created&quot;</span>) &lt;&lt; std::endl;</div>
<div class="line">        }</div>
<div class="line"></div>
<div class="line">        std::cout &lt;&lt; <span class="stringliteral">&quot;=&gt; Total fetched rows : &quot;</span> &lt;&lt; rs.<a class="code" href="classocilib_1_1_resultset.html#a704490bcf58c66f5021c626c0fc76b0b">GetCount</a>() &lt;&lt; std::endl;</div>
<div class="line"></div>
<div class="line">    }</div>
<div class="line">    <span class="keywordflow">catch</span> (std::exception &amp;ex)</div>
<div class="line">    {</div>
<div class="line">        std::cout &lt;&lt; ex.what() &lt;&lt; std::endl;</div>
<div class="line">    }</div>
<div class="line"></div>
<div class="line">    <a class="code" href="classocilib_1_1_environment.html#a8c21dd437c424a1f6cb63ed66441c979">Environment::Cleanup</a>();</div>
<div class="line"></div>
<div class="line">    <span class="keywordflow">return</span> EXIT_SUCCESS;</div>
<div class="line">}</div>
</div><!-- fragment --></dd></dl>
<dl class="section user"><dt>Binding vectors</dt><dd><div class="fragment"><div class="line"><span class="preprocessor">#include &lt;iostream&gt;</span></div>
<div class="line"></div>
<div class="line"><span class="preprocessor">#include &quot;ocilib.hpp&quot;</span></div>
<div class="line"></div>
<div class="line"><span class="keyword">using namespace </span><a class="code" href="namespaceocilib.html">ocilib</a>;</div>
<div class="line"></div>
<div class="line"><span class="keyword">const</span> <span class="keywordtype">int</span> ArraySize = 1000;</div>
<div class="line"></div>
<div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">void</span>)</div>
<div class="line">{</div>
<div class="line">    <span class="keywordflow">try</span></div>
<div class="line">    {</div>
<div class="line">        <a class="code" href="classocilib_1_1_environment.html#a83613d62908717ddf7d0ac797d63120a">Environment::Initialize</a>();</div>
<div class="line"></div>
<div class="line">        <a class="code" href="classocilib_1_1_connection.html">Connection</a> con(<span class="stringliteral">&quot;db&quot;</span>, <span class="stringliteral">&quot;usr&quot;</span>, <span class="stringliteral">&quot;pwd&quot;</span>);</div>
<div class="line"></div>
<div class="line">        std::vector&lt;int&gt; ints;</div>
<div class="line">        std::vector&lt;ostring&gt; strs;</div>
<div class="line"></div>
<div class="line">        <a class="code" href="classocilib_1_1_statement.html">Statement</a> st(con);</div>
<div class="line">        st.Prepare(<span class="stringliteral">&quot;insert into products values(:i, :s)&quot;</span>);</div>
<div class="line">        st.SetBindArraySize(ArraySize);</div>
<div class="line">        st.Bind(<span class="stringliteral">&quot;:i&quot;</span>, ints, <a class="code" href="classocilib_1_1_bind_info.html#a08f96498d216e0ad14ab8e7a35406533a026e00fee6fd4ae470376643180eba05">BindInfo::In</a>);</div>
<div class="line">        st.Bind(<span class="stringliteral">&quot;:s&quot;</span>, strs, 20, <a class="code" href="classocilib_1_1_bind_info.html#a08f96498d216e0ad14ab8e7a35406533a026e00fee6fd4ae470376643180eba05">BindInfo::In</a>);</div>
<div class="line"></div>
<div class="line">        <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i&lt;ArraySize; i++)</div>
<div class="line">        {</div>
<div class="line">            <a class="code" href="namespaceocilib.html#a01daa07e307e429b66fb80f442362237">ostring</a> str;</div>
<div class="line">            str += <span class="stringliteral">&quot;Name&quot;</span>;</div>
<div class="line">            str += ((i + 1) + <span class="charliteral">&#39;0&#39;</span>);</div>
<div class="line"></div>
<div class="line">            ints.push_back(i + 1);</div>
<div class="line">            strs.push_back(str);</div>
<div class="line">        }</div>
<div class="line"></div>
<div class="line">        st.ExecutePrepared();</div>
<div class="line"></div>
<div class="line">        std::cout &lt;&lt; <span class="stringliteral">&quot;row processed : &quot;</span> &lt;&lt; st.GetAffectedRows() &lt;&lt; std::endl;</div>
<div class="line"></div>
<div class="line">    }</div>
<div class="line">    <span class="keywordflow">catch</span> (std::exception &amp;ex)</div>
<div class="line">    {</div>
<div class="line">        std::cout &lt;&lt; ex.what() &lt;&lt; std::endl;</div>
<div class="line">    }</div>
<div class="line"></div>
<div class="line">    <a class="code" href="classocilib_1_1_environment.html#a8c21dd437c424a1f6cb63ed66441c979">Environment::Cleanup</a>();</div>
<div class="line"></div>
<div class="line">    <span class="keywordflow">return</span> EXIT_SUCCESS;</div>
<div class="line">}</div>
</div><!-- fragment --></dd></dl>
<dl class="section user"><dt>Using collections</dt><dd><div class="fragment"><div class="line"><span class="preprocessor">#include &lt;iostream&gt;</span></div>
<div class="line"></div>
<div class="line"><span class="preprocessor">#include &quot;ocilib.hpp&quot;</span></div>
<div class="line"></div>
<div class="line"><span class="keyword">using namespace </span><a class="code" href="namespaceocilib.html">ocilib</a>;</div>
<div class="line"></div>
<div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">void</span>)</div>
<div class="line">{</div>
<div class="line">    <span class="keywordflow">try</span></div>
<div class="line">    {</div>
<div class="line">        <a class="code" href="classocilib_1_1_environment.html#a83613d62908717ddf7d0ac797d63120a">Environment::Initialize</a>();</div>
<div class="line"></div>
<div class="line">        <a class="code" href="classocilib_1_1_connection.html">Connection</a> con(<span class="stringliteral">&quot;db&quot;</span>, <span class="stringliteral">&quot;usr&quot;</span>, <span class="stringliteral">&quot;pwd&quot;</span>);</div>
<div class="line">        <a class="code" href="classocilib_1_1_statement.html">Statement</a> st(con);</div>
<div class="line"></div>
<div class="line">        <span class="comment">/* bind local collection to a PL/SQL procedure */</span></div>
<div class="line"></div>
<div class="line">        <a class="code" href="classocilib_1_1_collection.html">Collection&lt;ostring&gt;</a> coll1(<a class="code" href="classocilib_1_1_type_info.html">TypeInfo</a>(con, <span class="stringliteral">&quot;varray_type&quot;</span>, <a class="code" href="classocilib_1_1_type_info.html#a7369d09e8bd979f61371c80c46ee894eaa7acfaf3f68a4866b13bd14b7e7611ca">TypeInfo::Type</a>));</div>
<div class="line"></div>
<div class="line">        st.Prepare(<span class="stringliteral">&quot;begin load_array(:coll); end;&quot;</span>);</div>
<div class="line">        st.Bind(<span class="stringliteral">&quot;:coll&quot;</span>, coll1, <a class="code" href="classocilib_1_1_bind_info.html#a08f96498d216e0ad14ab8e7a35406533a026e00fee6fd4ae470376643180eba05">BindInfo::In</a>);</div>
<div class="line">        st.ExecutePrepared();</div>
<div class="line"></div>
<div class="line">        <a class="code" href="classocilib_1_1_collection_1_1_iterator.html">Collection&lt;ostring&gt;::iterator</a> it1 = coll1.<a class="code" href="classocilib_1_1_collection.html#a5e44fc261abbfad92fe2ed7a6eea1e21">begin</a>();</div>
<div class="line">        <a class="code" href="classocilib_1_1_collection_1_1_iterator.html">Collection&lt;ostring&gt;::iterator</a> it2 = coll1.end();</div>
<div class="line"></div>
<div class="line">        <span class="keywordflow">for</span> (; it1 != it2; ++it1)</div>
<div class="line">        {</div>
<div class="line">            std::cout &lt;&lt; <span class="stringliteral">&quot;value &quot;</span> &lt;&lt; <span class="keyword">static_cast&lt;</span><a class="code" href="namespaceocilib.html#a01daa07e307e429b66fb80f442362237">ostring</a><span class="keyword">&gt;</span>(*it1) &lt;&lt; std::endl;</div>
<div class="line">        }</div>
<div class="line"></div>
<div class="line">        <span class="comment">/* query on a table with varray column */</span></div>
<div class="line"></div>
<div class="line">        st.Execute(<span class="stringliteral">&quot;SELECT products from items&quot;</span>);</div>
<div class="line"></div>
<div class="line">        <a class="code" href="classocilib_1_1_resultset.html">Resultset</a> rs = st.GetResultset();</div>
<div class="line">        <span class="keywordflow">while</span> (rs++)</div>
<div class="line">        {</div>
<div class="line">            <a class="code" href="classocilib_1_1_collection.html">Collection&lt;Object&gt;</a> coll2 = rs.<a class="code" href="classocilib_1_1_resultset.html#aeaea5cd57d9b6838f3887ed57338acb8">Get</a>&lt;<a class="code" href="classocilib_1_1_collection.html">Collection&lt;Object&gt;</a>&gt;(<span class="stringliteral">&quot;products&quot;</span>);</div>
<div class="line">            <a class="code" href="classocilib_1_1_collection_1_1_iterator.html">Collection&lt;Object&gt;::iterator</a> it1 = coll2.<a class="code" href="classocilib_1_1_collection.html#a5e44fc261abbfad92fe2ed7a6eea1e21">begin</a>();</div>
<div class="line">            <a class="code" href="classocilib_1_1_collection_1_1_iterator.html">Collection&lt;Object&gt;::iterator</a> it2 = coll2.<a class="code" href="classocilib_1_1_collection.html#a60f26feeb248aa5962f7c1fdb7dc8120">end</a>();</div>
<div class="line"></div>
<div class="line">            <span class="keywordflow">for</span> (; it1 != it2; ++it1)</div>
<div class="line">            {</div>
<div class="line">                <a class="code" href="classocilib_1_1_object.html">Object</a> obj = *it1;</div>
<div class="line"></div>
<div class="line">                std::cout &lt;&lt; <span class="stringliteral">&quot;... product id : &quot;</span> &lt;&lt; obj.<a class="code" href="classocilib_1_1_object.html#a7212cec642dc5ce7c9419b3925266e9f">Get</a>&lt;<span class="keywordtype">int</span>&gt;(<span class="stringliteral">&quot;Id&quot;</span>) &lt;&lt; <span class="stringliteral">&quot;, name : &quot;</span> &lt;&lt; obj.<a class="code" href="classocilib_1_1_object.html#a7212cec642dc5ce7c9419b3925266e9f">Get</a>&lt;<a class="code" href="namespaceocilib.html#a01daa07e307e429b66fb80f442362237">ostring</a>&gt;(<span class="stringliteral">&quot;Name&quot;</span>) &lt;&lt; std::endl;</div>
<div class="line">            }</div>
<div class="line">        }</div>
<div class="line">    }</div>
<div class="line">    <span class="keywordflow">catch</span> (std::exception &amp;ex)</div>
<div class="line">    {</div>
<div class="line">        std::cout &lt;&lt; ex.what() &lt;&lt; std::endl;</div>
<div class="line">    }</div>
<div class="line"></div>
<div class="line">    <a class="code" href="classocilib_1_1_environment.html#a8c21dd437c424a1f6cb63ed66441c979">Environment::Cleanup</a>();</div>
<div class="line"></div>
<div class="line">    <span class="keywordflow">return</span> EXIT_SUCCESS;</div>
<div class="line">}</div>
</div><!-- fragment --></dd></dl>
<dl class="section user"><dt>Using connection pools</dt><dd><div class="fragment"><div class="line"><span class="preprocessor">#include &lt;iostream&gt;</span></div>
<div class="line"></div>
<div class="line"><span class="preprocessor">#include &quot;ocilib.hpp&quot;</span></div>
<div class="line"></div>
<div class="line"><span class="keyword">using namespace </span><a class="code" href="namespaceocilib.html">ocilib</a>;</div>
<div class="line"></div>
<div class="line"><span class="keyword">const</span> <span class="keywordtype">int</span> MaxThreads = 50;</div>
<div class="line"><span class="keyword">const</span> <span class="keywordtype">int</span> MaxConnnections = 10;</div>
<div class="line"></div>
<div class="line"><span class="keywordtype">void</span> worker(<a class="code" href="namespaceocilib.html#ae6a65e2d9f68cf3bb5d1ea4f68e8db59">ThreadHandle</a> handle, <span class="keywordtype">void</span> *data)</div>
<div class="line">{</div>
<div class="line">    <a class="code" href="classocilib_1_1_connection.html">Connection</a> con = ((<a class="code" href="classocilib_1_1_pool.html">Pool</a> *)data)-&gt;GetConnection();</div>
<div class="line">    <a class="code" href="classocilib_1_1_statement.html">Statement</a> st(con);</div>
<div class="line">    st.Execute(<span class="stringliteral">&quot;select to_char(sysdate, &#39;YYYYMMDD HH24:MI:SS&#39;) from dual&quot;</span>);</div>
<div class="line">    <a class="code" href="classocilib_1_1_resultset.html">Resultset</a> rs = st.GetResultset();</div>
<div class="line">    rs.<a class="code" href="classocilib_1_1_resultset.html#adc767eeaed4b12ce26c8d25eebe6889c">Next</a>();</div>
<div class="line">    std::cout &lt;&lt; handle &lt;&lt; <span class="stringliteral">&quot; - &quot;</span> &lt;&lt; rs.<a class="code" href="classocilib_1_1_resultset.html#aeaea5cd57d9b6838f3887ed57338acb8">Get</a>&lt;<a class="code" href="namespaceocilib.html#a01daa07e307e429b66fb80f442362237">ostring</a>&gt;(1) &lt;&lt; std::endl;</div>
<div class="line">    con.<a class="code" href="classocilib_1_1_connection.html#a765afaee0c7d73c9dc0690a89db47955">Close</a>();</div>
<div class="line">}</div>
<div class="line"></div>
<div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">void</span>)</div>
<div class="line">{</div>
<div class="line">    <span class="keywordflow">try</span></div>
<div class="line">    {</div>
<div class="line">        <a class="code" href="classocilib_1_1_environment.html#a83613d62908717ddf7d0ac797d63120a">Environment::Initialize</a>(Environment::Threaded);</div>
<div class="line"></div>
<div class="line">        <a class="code" href="classocilib_1_1_pool.html">Pool</a> pool(<span class="stringliteral">&quot;db&quot;</span>, <span class="stringliteral">&quot;usr&quot;</span>, <span class="stringliteral">&quot;pwd&quot;</span>, <a class="code" href="classocilib_1_1_pool.html#a52ee2b1e8d5039f64a18fe343fbb191eae703388104ab6daf2f01a90c61115543">Pool::ConnectionPool</a>, 0, MaxConnnections);</div>
<div class="line"></div>
<div class="line">        std::vector&lt;ThreadHandle&gt; threads;</div>
<div class="line"></div>
<div class="line">        <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; MaxThreads; i++)</div>
<div class="line">        {</div>
<div class="line">            <a class="code" href="namespaceocilib.html#ae6a65e2d9f68cf3bb5d1ea4f68e8db59">ThreadHandle</a> th = <a class="code" href="classocilib_1_1_thread.html#aa8ea3f3d52603301bee5d1778cc871d7">Thread::Create</a>();</div>
<div class="line">            threads.push_back(th);</div>
<div class="line">            <a class="code" href="classocilib_1_1_thread.html#a3703d465704b99c4896b70510ca768c5">Thread::Run</a>(th, worker, &amp;pool);</div>
<div class="line">        }</div>
<div class="line"></div>
<div class="line">        <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; MaxThreads; i++)</div>
<div class="line">        {</div>
<div class="line">            <a class="code" href="classocilib_1_1_thread.html#af55c3998611320a10f4c2f62c697de62">Thread::Join</a>(threads[i]);</div>
<div class="line">            <a class="code" href="classocilib_1_1_thread.html#af672a19847e798b83fe3f5d7dd0ba16c">Thread::Destroy</a>(threads[i]);</div>
<div class="line">        }</div>
<div class="line">    }</div>
<div class="line">    <span class="keywordflow">catch</span> (std::exception &amp;ex)</div>
<div class="line">    {</div>
<div class="line">        std::cout &lt;&lt; ex.what() &lt;&lt; std::endl;</div>
<div class="line">    }</div>
<div class="line"></div>
<div class="line">    <a class="code" href="classocilib_1_1_environment.html#a8c21dd437c424a1f6cb63ed66441c979">Environment::Cleanup</a>();</div>
<div class="line"></div>
<div class="line">    <span class="keywordflow">return</span> EXIT_SUCCESS;</div>
<div class="line">}</div>
</div><!-- fragment --></dd></dl>
<dl class="section user"><dt>Oracle 12c Implicit resultsets</dt><dd><div class="fragment"><div class="line"><span class="preprocessor">#include &lt;iostream&gt;</span></div>
<div class="line"></div>
<div class="line"><span class="preprocessor">#include &quot;ocilib.hpp&quot;</span></div>
<div class="line"></div>
<div class="line"><span class="keyword">using namespace </span><a class="code" href="namespaceocilib.html">ocilib</a>;</div>
<div class="line"></div>
<div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">void</span>)</div>
<div class="line">{</div>
<div class="line">    <span class="keywordflow">try</span></div>
<div class="line">    {</div>
<div class="line">        <a class="code" href="classocilib_1_1_environment.html#a83613d62908717ddf7d0ac797d63120a">Environment::Initialize</a>();</div>
<div class="line"></div>
<div class="line">        <a class="code" href="classocilib_1_1_connection.html">Connection</a> con(<span class="stringliteral">&quot;db&quot;</span>, <span class="stringliteral">&quot;usr&quot;</span>, <span class="stringliteral">&quot;pwd&quot;</span>);</div>
<div class="line"></div>
<div class="line">        <a class="code" href="classocilib_1_1_statement.html">Statement</a> st(con);</div>
<div class="line">        st.Execute(<span class="stringliteral">&quot;declare&quot;</span></div>
<div class="line">            <span class="stringliteral">&quot;  c1 sys_refcursor;&quot;</span></div>
<div class="line">            <span class="stringliteral">&quot;  c2 sys_refcursor;&quot;</span></div>
<div class="line">            <span class="stringliteral">&quot; begin&quot;</span></div>
<div class="line">            <span class="stringliteral">&quot;  open c1 for select username from all_users;&quot;</span></div>
<div class="line">            <span class="stringliteral">&quot;  dbms_sql.return_result (c1); &quot;</span></div>
<div class="line">            <span class="stringliteral">&quot;  open c2 for select table_name from all_tables;&quot;</span></div>
<div class="line">            <span class="stringliteral">&quot;  dbms_sql.return_result (c2); &quot;</span></div>
<div class="line">            <span class="stringliteral">&quot;end;&quot;</span>);</div>
<div class="line"></div>
<div class="line">        <a class="code" href="classocilib_1_1_resultset.html">Resultset</a> rs = st.GetResultset();</div>
<div class="line"></div>
<div class="line">        <span class="keywordflow">while</span> (rs)</div>
<div class="line">        {</div>
<div class="line">            <span class="keywordflow">while</span> (rs++)</div>
<div class="line">            {</div>
<div class="line">                std::cout &lt;&lt; <span class="stringliteral">&quot;Fetch column name:&quot;</span> &lt;&lt; rs.<a class="code" href="classocilib_1_1_resultset.html#af7585acb43fc8d54ae025fe1d5c9d7d1">GetColumn</a>(1).GetName() &lt;&lt; <span class="stringliteral">&quot;, Value:&quot;</span> &lt;&lt; rs.<a class="code" href="classocilib_1_1_resultset.html#aeaea5cd57d9b6838f3887ed57338acb8">Get</a>&lt;<a class="code" href="namespaceocilib.html#a01daa07e307e429b66fb80f442362237">ostring</a>&gt;(1) &lt;&lt; std::endl;</div>
<div class="line">            }</div>
<div class="line"></div>
<div class="line">            std::cout &lt;&lt; <span class="stringliteral">&quot;=&gt; Total fetched rows : &quot;</span> &lt;&lt; rs.<a class="code" href="classocilib_1_1_resultset.html#a704490bcf58c66f5021c626c0fc76b0b">GetCount</a>() &lt;&lt; std::endl;</div>
<div class="line"></div>
<div class="line">            rs = st.GetNextResultset();</div>
<div class="line">        }</div>
<div class="line">    }</div>
<div class="line">    <span class="keywordflow">catch</span> (std::exception &amp;ex)</div>
<div class="line">    {</div>
<div class="line">        std::cout &lt;&lt; ex.what() &lt;&lt; std::endl;</div>
<div class="line">    }</div>
<div class="line"></div>
<div class="line">    <a class="code" href="classocilib_1_1_environment.html#a8c21dd437c424a1f6cb63ed66441c979">Environment::Cleanup</a>();</div>
<div class="line"></div>
<div class="line">    <span class="keywordflow">return</span> EXIT_SUCCESS;</div>
<div class="line">}</div>
</div><!-- fragment --></dd></dl>
<dl class="section user"><dt>Using Oracle objects</dt><dd><div class="fragment"><div class="line"><span class="preprocessor">#include &lt;iostream&gt;</span></div>
<div class="line"></div>
<div class="line"><span class="preprocessor">#include &quot;ocilib.hpp&quot;</span></div>
<div class="line"></div>
<div class="line"><span class="comment">/*</span></div>
<div class="line"><span class="comment">DML for the test</span></div>
<div class="line"><span class="comment"></span></div>
<div class="line"><span class="comment">create type t_vendor as object</span></div>
<div class="line"><span class="comment">(</span></div>
<div class="line"><span class="comment">code  number,</span></div>
<div class="line"><span class="comment">name  varchar2(30)</span></div>
<div class="line"><span class="comment">);</span></div>
<div class="line"><span class="comment">/</span></div>
<div class="line"><span class="comment">create type t_sale as object</span></div>
<div class="line"><span class="comment">(</span></div>
<div class="line"><span class="comment">code  number,</span></div>
<div class="line"><span class="comment">price  float,</span></div>
<div class="line"><span class="comment">name  varchar2(30),</span></div>
<div class="line"><span class="comment">ref  varchar2(30),</span></div>
<div class="line"><span class="comment">date_sale date,</span></div>
<div class="line"><span class="comment">vendor  t_vendor</span></div>
<div class="line"><span class="comment">);</span></div>
<div class="line"><span class="comment">/</span></div>
<div class="line"><span class="comment">create table sales(item t_sale);</span></div>
<div class="line"><span class="comment"></span></div>
<div class="line"><span class="comment">*/</span></div>
<div class="line"></div>
<div class="line"><span class="keyword">using namespace </span><a class="code" href="namespaceocilib.html">ocilib</a>;</div>
<div class="line"></div>
<div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">void</span>)</div>
<div class="line">{</div>
<div class="line">    <span class="keywordflow">try</span></div>
<div class="line">    {</div>
<div class="line">        <a class="code" href="classocilib_1_1_environment.html#a83613d62908717ddf7d0ac797d63120a">Environment::Initialize</a>();</div>
<div class="line"></div>
<div class="line">        <a class="code" href="classocilib_1_1_connection.html">Connection</a> con(<span class="stringliteral">&quot;db&quot;</span>, <span class="stringliteral">&quot;usr&quot;</span>, <span class="stringliteral">&quot;pwd&quot;</span>);</div>
<div class="line"></div>
<div class="line">        <a class="code" href="classocilib_1_1_date.html">Date</a> date;</div>
<div class="line">        date.<a class="code" href="classocilib_1_1_date.html#a5d7ee0191341605450e52102ad6a92f7">SysDate</a>();</div>
<div class="line"></div>
<div class="line">        <a class="code" href="classocilib_1_1_object.html">Object</a> sale(<a class="code" href="classocilib_1_1_type_info.html">TypeInfo</a>(con, <span class="stringliteral">&quot;t_sale&quot;</span>, <a class="code" href="classocilib_1_1_type_info.html#a7369d09e8bd979f61371c80c46ee894eaa7acfaf3f68a4866b13bd14b7e7611ca">TypeInfo::Type</a>));</div>
<div class="line">        <a class="code" href="classocilib_1_1_object.html">Object</a> vendor(<a class="code" href="classocilib_1_1_type_info.html">TypeInfo</a>(con, <span class="stringliteral">&quot;t_vendor&quot;</span>, <a class="code" href="classocilib_1_1_type_info.html#a7369d09e8bd979f61371c80c46ee894eaa7acfaf3f68a4866b13bd14b7e7611ca">TypeInfo::Type</a>));</div>
<div class="line"></div>
<div class="line">        vendor.Set&lt;<span class="keywordtype">int</span>&gt;(<span class="stringliteral">&quot;CODE&quot;</span>, 134);</div>
<div class="line">        vendor.Set&lt;<a class="code" href="namespaceocilib.html#a01daa07e307e429b66fb80f442362237">ostring</a>&gt;(<span class="stringliteral">&quot;NAME&quot;</span>, <span class="stringliteral">&quot;JOHN SMITH&quot;</span>);</div>
<div class="line"></div>
<div class="line">        sale.Set&lt;<span class="keywordtype">int</span>&gt;(<span class="stringliteral">&quot;CODE&quot;</span>, 1);</div>
<div class="line">        sale.Set&lt;<span class="keywordtype">double</span>&gt;(<span class="stringliteral">&quot;PRICE&quot;</span>, 12.99);</div>
<div class="line">        sale.Set&lt;<a class="code" href="namespaceocilib.html#a01daa07e307e429b66fb80f442362237">ostring</a>&gt;(<span class="stringliteral">&quot;NAME&quot;</span>, <span class="stringliteral">&quot;USB KEY 2go&quot;</span>);</div>
<div class="line">        sale.Set&lt;<a class="code" href="namespaceocilib.html#a01daa07e307e429b66fb80f442362237">ostring</a>&gt;(<span class="stringliteral">&quot;REF&quot;</span>, <span class="stringliteral">&quot;A56547WSAA&quot;</span>);</div>
<div class="line">        sale.Set&lt;<a class="code" href="classocilib_1_1_date.html">Date</a>&gt;(<span class="stringliteral">&quot;DATE_SALE&quot;</span>, date);</div>
<div class="line">        sale.Set&lt;<a class="code" href="classocilib_1_1_object.html">Object</a>&gt;(<span class="stringliteral">&quot;VENDOR&quot;</span>, vendor);</div>
<div class="line"></div>
<div class="line">        <a class="code" href="classocilib_1_1_statement.html">Statement</a> st(con);</div>
<div class="line">        st.Prepare(<span class="stringliteral">&quot;insert into sales values(:obj)&quot;</span>);</div>
<div class="line">        st.Bind(<span class="stringliteral">&quot;:obj&quot;</span>, sale, <a class="code" href="classocilib_1_1_bind_info.html#a08f96498d216e0ad14ab8e7a35406533a026e00fee6fd4ae470376643180eba05">BindInfo::In</a>);</div>
<div class="line">        st.ExecutePrepared();</div>
<div class="line"></div>
<div class="line">        std::cout &lt;&lt; <span class="stringliteral">&quot;Rows inserted :  &quot;</span> &lt;&lt; st.GetAffectedRows() &lt;&lt; std::endl;</div>
<div class="line"></div>
<div class="line">        con.<a class="code" href="classocilib_1_1_connection.html#a5875666074d5c8b9cfb1f5660f176757">Commit</a>();</div>
<div class="line">    }</div>
<div class="line">    <span class="keywordflow">catch</span> (std::exception &amp;ex)</div>
<div class="line">    {</div>
<div class="line">        std::cout &lt;&lt; ex.what() &lt;&lt; std::endl;</div>
<div class="line">    }</div>
<div class="line"></div>
<div class="line">    <a class="code" href="classocilib_1_1_environment.html#a8c21dd437c424a1f6cb63ed66441c979">Environment::Cleanup</a>();</div>
<div class="line"></div>
<div class="line">    <span class="keywordflow">return</span> EXIT_SUCCESS;</div>
<div class="line">}</div>
</div><!-- fragment --></dd></dl>
<dl class="section user"><dt>Database notifications</dt><dd><div class="fragment"><div class="line"><span class="preprocessor">#include &lt;iostream&gt;</span></div>
<div class="line"></div>
<div class="line"><span class="preprocessor">#include &quot;ocilib.hpp&quot;</span></div>
<div class="line"></div>
<div class="line"><span class="keyword">using namespace </span><a class="code" href="namespaceocilib.html">ocilib</a>;</div>
<div class="line"></div>
<div class="line"><span class="preprocessor">#ifdef _WINDOWS</span></div>
<div class="line"><span class="preprocessor">#define sleep(x) Sleep(x*1000)</span></div>
<div class="line"><span class="preprocessor">#endif</span></div>
<div class="line"></div>
<div class="line"><span class="preprocessor">#define WaitForEvents()   sleep(5)</span></div>
<div class="line"><span class="preprocessor">#define WaitForDatabase() sleep(60)</span></div>
<div class="line"></div>
<div class="line"></div>
<div class="line"><span class="keyword">static</span> std::map&lt;unsigned int, ostring&gt; EventTypes;</div>
<div class="line"><span class="keyword">static</span> std::map&lt;unsigned int, ostring&gt; ObjectEvents;</div>
<div class="line"></div>
<div class="line"><span class="keywordtype">void</span> EventHandler(<a class="code" href="classocilib_1_1_event.html">Event</a> &amp;evt);</div>
<div class="line"><span class="keywordtype">void</span> SetupNames();</div>
<div class="line"></div>
<div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span>* argv[])</div>
<div class="line">{</div>
<div class="line">    SetupNames();</div>
<div class="line">    <span class="keywordflow">try</span></div>
<div class="line">    {</div>
<div class="line">        <a class="code" href="classocilib_1_1_environment.html#a83613d62908717ddf7d0ac797d63120a">Environment::Initialize</a>(<a class="code" href="classocilib_1_1_environment.html#a87b82fd52f230a521416ee49e2ace788a64dea47e6ace702d102d856a6401ecaa">Environment::Events</a>);</div>
<div class="line"></div>
<div class="line">        <a class="code" href="classocilib_1_1_connection.html">Connection</a> con(<span class="stringliteral">&quot;db&quot;</span>, <span class="stringliteral">&quot;usr&quot;</span>, <span class="stringliteral">&quot;pwd&quot;</span>);</div>
<div class="line">        con.<a class="code" href="classocilib_1_1_connection.html#a8e6f6ed2cf7556ed33f142ab6a603526">SetAutoCommit</a>(<span class="keyword">true</span>);</div>
<div class="line"></div>
<div class="line">        <a class="code" href="classocilib_1_1_statement.html">Statement</a> st(con);</div>
<div class="line">        st.Execute(<span class="stringliteral">&quot;create table table1(code number)&quot;</span>);</div>
<div class="line">        st.Execute(<span class="stringliteral">&quot;create table table2(str varchar2(10))&quot;</span>);</div>
<div class="line"></div>
<div class="line">        <a class="code" href="classocilib_1_1_subscription.html">Subscription</a> sub;</div>
<div class="line">        sub.<a class="code" href="classocilib_1_1_subscription.html#a44f8bca8a9479fe38dde565890850389">Register</a>(con, <span class="stringliteral">&quot;sub-00&quot;</span>, <a class="code" href="classocilib_1_1_subscription.html#aa2667ca0384af70f0c17d6bdc28ed082a5a55eb308dfae1200c7d22df8957aa3a">Subscription::AllChanges</a>, EventHandler, 5468, 0);</div>
<div class="line">        sub.<a class="code" href="classocilib_1_1_subscription.html#a0bbced3f0c3111880bff1d9f8b607a38">Watch</a>(<span class="stringliteral">&quot;select * from table1&quot;</span>);</div>
<div class="line">        sub.<a class="code" href="classocilib_1_1_subscription.html#a0bbced3f0c3111880bff1d9f8b607a38">Watch</a>(<span class="stringliteral">&quot;select * from table2&quot;</span>);</div>
<div class="line"></div>
<div class="line">        st.Execute(<span class="stringliteral">&quot;alter table table1 add price number&quot;</span>);</div>
<div class="line">        WaitForEvents();</div>
<div class="line"></div>
<div class="line">        st.Execute(<span class="stringliteral">&quot;insert into table1 values(1, 10.5)&quot;</span>);</div>
<div class="line">        st.Execute(<span class="stringliteral">&quot;insert into table2 values(&#39;shoes&#39;)&quot;</span>);</div>
<div class="line">        WaitForEvents();</div>
<div class="line"></div>
<div class="line">        st.Execute(<span class="stringliteral">&quot;update table1 set price = 13.5 where code = 1&quot;</span>);</div>
<div class="line">        st.Execute(<span class="stringliteral">&quot;delete from table2 &quot;</span>);</div>
<div class="line">        WaitForEvents();</div>
<div class="line"></div>
<div class="line">        st.Execute(<span class="stringliteral">&quot;drop table table1&quot;</span>);</div>
<div class="line">        st.Execute(<span class="stringliteral">&quot;drop table table2&quot;</span>);</div>
<div class="line">        WaitForEvents();</div>
<div class="line"></div>
<div class="line">        con.<a class="code" href="classocilib_1_1_connection.html#a765afaee0c7d73c9dc0690a89db47955">Close</a>();</div>
<div class="line"></div>
<div class="line">        <span class="comment">/* start remote instance */</span></div>
<div class="line">        <a class="code" href="classocilib_1_1_environment.html#a7165adb4dffe98f8ae5fcf5829f591b3">Environment::StartDatabase</a>(<span class="stringliteral">&quot;db&quot;</span>, <span class="stringliteral">&quot;sys_usr&quot;</span>, <span class="stringliteral">&quot;sys_pwd&quot;</span>, <a class="code" href="classocilib_1_1_environment.html#a323b1b9f91731ba7af891c5b8f33cff9a3843f4e33a04e811887a019e2d87a3e6">Environment::StartForce</a>, <a class="code" href="classocilib_1_1_environment.html#a13bc1c46153530664fba7e79a8fad6faa1217e5b2be5bdb014808c231a104646e">Environment::StartFull</a>);</div>
<div class="line"></div>
<div class="line">        <span class="comment">/* shutdown remote instance */</span></div>
<div class="line">        <a class="code" href="classocilib_1_1_environment.html#a13cfb9869267de416ecf18671c7002e3">Environment::ShutdownDatabase</a>(<span class="stringliteral">&quot;db&quot;</span>, <span class="stringliteral">&quot;sys_usr&quot;</span>, <span class="stringliteral">&quot;sys_pwd&quot;</span>, <a class="code" href="classocilib_1_1_environment.html#a45b76afea0bc2e821b60f7a0d2d38f5eade5e8adcc3a72196be4048a74ade6ffa">Environment::ShutdownAbort</a>, <a class="code" href="classocilib_1_1_environment.html#adf147cb0c33421a41603036e10503c84adcd70bff9f96f5a926a5686f88b90822">Environment::ShutdownFull</a>);</div>
<div class="line">        WaitForDatabase();</div>
<div class="line"></div>
<div class="line">        sub.<a class="code" href="classocilib_1_1_subscription.html#a1f6e12327beee0faef2d15e0244d090a">Unregister</a>();</div>
<div class="line"></div>
<div class="line">    }</div>
<div class="line">    <span class="keywordflow">catch</span> (std::exception &amp;ex)</div>
<div class="line">    {</div>
<div class="line">        std::cout &lt;&lt; ex.what() &lt;&lt; std::endl;</div>
<div class="line">    }</div>
<div class="line"></div>
<div class="line">    <a class="code" href="classocilib_1_1_environment.html#a8c21dd437c424a1f6cb63ed66441c979">Environment::Cleanup</a>();</div>
<div class="line">}</div>
<div class="line"></div>
<div class="line"><span class="keywordtype">void</span> SetupNames()</div>
<div class="line">{</div>
<div class="line">    EventTypes[<a class="code" href="classocilib_1_1_event.html#a870a4e6122a5258f3a2291414581383ea830b8a12508b6691d83a62689e07d643">Event::DatabaseStart</a>] = <span class="stringliteral">&quot;Startup&quot;</span>;</div>
<div class="line">    EventTypes[<a class="code" href="classocilib_1_1_event.html#a870a4e6122a5258f3a2291414581383eacef7d0bc6849aed59c435d39bb753665">Event::DatabaseShutdown</a>] = <span class="stringliteral">&quot;Shutdown&quot;</span>;</div>
<div class="line">    EventTypes[<a class="code" href="classocilib_1_1_event.html#a870a4e6122a5258f3a2291414581383ea0413ea4c9e3fe486ddda39189a8c6766">Event::DatabaseShutdownAny</a>] = <span class="stringliteral">&quot;Shutdown Any&quot;</span>;</div>
<div class="line">    EventTypes[<a class="code" href="classocilib_1_1_event.html#a870a4e6122a5258f3a2291414581383eaae6d29812ffeffa0db1ae1f26fd03010">Event::DatabaseDrop</a>] = <span class="stringliteral">&quot;Drop Database&quot;</span>;</div>
<div class="line">    EventTypes[<a class="code" href="classocilib_1_1_event.html#a870a4e6122a5258f3a2291414581383ead90ec9724417d56869f76366a04bdcae">Event::Unregister</a>] = <span class="stringliteral">&quot;Unregister&quot;</span>;</div>
<div class="line">    EventTypes[<a class="code" href="classocilib_1_1_event.html#a870a4e6122a5258f3a2291414581383ead2402566e03ab9dd521f1d03c0a6bc13">Event::ObjectChanged</a>] = <span class="stringliteral">&quot;Object Changed&quot;</span>;</div>
<div class="line"></div>
<div class="line">    ObjectEvents[<a class="code" href="classocilib_1_1_event.html#a019d692c5e22a1c59dcfc640ae19f679a23ec39bcce48de5de8de254aa69a4287">Event::ObjectInserted</a>] = <span class="stringliteral">&quot;Insert&quot;</span>;</div>
<div class="line">    ObjectEvents[<a class="code" href="classocilib_1_1_event.html#a019d692c5e22a1c59dcfc640ae19f679a7359bd27010684be6931c81aaa4855eb">Event::ObjectUpdated</a>] = <span class="stringliteral">&quot;Update&quot;</span>;</div>
<div class="line">    ObjectEvents[<a class="code" href="classocilib_1_1_event.html#a019d692c5e22a1c59dcfc640ae19f679a434786cacac73211795629dccc34d417">Event::ObjectDeleted</a>] = <span class="stringliteral">&quot;Delete&quot;</span>;</div>
<div class="line">    ObjectEvents[<a class="code" href="classocilib_1_1_event.html#a019d692c5e22a1c59dcfc640ae19f679ac2d3e43dae3f7e7c39da1a7600be04a9">Event::ObjectAltered</a>] = <span class="stringliteral">&quot;Alter&quot;</span>;</div>
<div class="line">    ObjectEvents[<a class="code" href="classocilib_1_1_event.html#a019d692c5e22a1c59dcfc640ae19f679af7865c5e76785c0a0c0a7fc01e41ada5">Event::ObjectDropped</a>] = <span class="stringliteral">&quot;Drop&quot;</span>;</div>
<div class="line">    ObjectEvents[<a class="code" href="classocilib_1_1_event.html#a019d692c5e22a1c59dcfc640ae19f679a342c800268d4273d162804a90bc68f96">Event::ObjectGeneric</a>] = <span class="stringliteral">&quot;Generic&quot;</span>;</div>
<div class="line">}</div>
<div class="line"></div>
<div class="line"><span class="keywordtype">void</span> EventHandler(<a class="code" href="classocilib_1_1_event.html">Event</a> &amp;evt)</div>
<div class="line">{</div>
<div class="line">    std::cout &lt;&lt; <span class="stringliteral">&quot;** Notification : &quot;</span> &lt;&lt; evt.<a class="code" href="classocilib_1_1_event.html#afea9cc576043252bb27ed52b2b13f257">GetSubscription</a>().<a class="code" href="classocilib_1_1_subscription.html#abae63e20c73fdf494c6538bb78559e56">GetName</a>() &lt;&lt; std::endl;</div>
<div class="line">    std::cout &lt;&lt; <span class="stringliteral">&quot;** Database     : &quot;</span> &lt;&lt; evt.<a class="code" href="classocilib_1_1_event.html#a6c060227178b17fc97b02526e1707c08">GetDatabaseName</a>() &lt;&lt; std::endl;</div>
<div class="line">    std::cout &lt;&lt; <span class="stringliteral">&quot;** Event        : &quot;</span> &lt;&lt; EventTypes[evt.<a class="code" href="classocilib_1_1_event.html#a412601315112f24603345fc7dc9061ef">GetType</a>()] &lt;&lt; std::endl;</div>
<div class="line"></div>
<div class="line">    <span class="keywordflow">if</span> (evt.<a class="code" href="classocilib_1_1_event.html#a412601315112f24603345fc7dc9061ef">GetType</a>() == <a class="code" href="classocilib_1_1_event.html#a870a4e6122a5258f3a2291414581383ead2402566e03ab9dd521f1d03c0a6bc13">Event::ObjectChanged</a>)</div>
<div class="line">    {</div>
<div class="line">        std::cout &lt;&lt; <span class="stringliteral">&quot;.... Object : &quot;</span> &lt;&lt; evt.<a class="code" href="classocilib_1_1_event.html#a150ab653e087b76fdd9e4ca9a083afc1">GetObjectName</a>() &lt;&lt; std::endl;</div>
<div class="line">        std::cout &lt;&lt; <span class="stringliteral">&quot;.... Action : &quot;</span> &lt;&lt; ObjectEvents[evt.<a class="code" href="classocilib_1_1_event.html#ae8d1ec68b3c19c437ac94964356c3eca">GetObjectEvent</a>()] &lt;&lt; std::endl;</div>
<div class="line">        std::cout &lt;&lt; <span class="stringliteral">&quot;.... RowID  : &quot;</span> &lt;&lt; evt.<a class="code" href="classocilib_1_1_event.html#a2fa9783b57dfeabaef53ce19f2211575">GetRowID</a>() &lt;&lt; std::endl;</div>
<div class="line">    }</div>
<div class="line"></div>
<div class="line">    std::cout &lt;&lt; std::endl;</div>
<div class="line">}</div>
<div class="line"></div>
</div><!-- fragment --> </dd></dl>
</div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="footer">Generated on Mon Mar 21 2016 22:26:38 for OCILIB (C and C++ Driver for Oracle) by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.9.1 </li>
  </ul>
</div>
</body>
</html>
